package com.example.wifi_direct.ui.main

import android.content.Context
import cn.jzvd.JzvdStd
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.wifi_direct.R
import com.example.wifi_direct.ui.main.model.VideoModel

/**
 * RecyclerView Adapter
 */
class VideoListRvAdapter(var mContext: Context, var dataList: MutableList<VideoModel>) :
    BaseQuickAdapter<VideoModel, BaseViewHolder>(R.layout.item_video, dataList) {
    override fun convert(holder: BaseViewHolder, item: VideoModel) {
        val videoBean = dataList[holder.layoutPosition]
        val videoplayer = holder.getView<JzvdStd>(R.id.videoplayer)
        videoplayer.setUp(
            // 视频播放地址和视频标题
            // 需要播其他的就更换其他的播放地址和标题
            videoBean.videoUrl,
            videoBean.title
        )
        Glide.with(mContext)
            // 视频封面 想要更换就换掉后面的url地址
            .load(videoBean.coverUrl)
            .into(videoplayer.posterImageView)

        // logo
        Glide.with(mContext)
            // 视频封面 想要更换就换掉后面的url地址
            .load(videoBean.itemLogoUrl)
            .into(holder.getView(R.id.ivLogo))

        // item标题
        holder.setText(R.id.tvTitle,videoBean.itemTitle)
        // item描述
        holder.setText(R.id.tvDesc,videoBean.itemDesc)
    }
}